home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 352_01.zip / STRPPTRM.CPP < prev    next >
C/C++ Source or Header  |  1993-04-10  |  718b  |  38 lines

  1. /* STRPPTRM.CPP        contains String::trim() 
  2.  *        string trim operation.
  3.  */
  4. #include <stdlib.h>
  5. #include <string.h> 
  6.  
  7. #include "dblib.h"
  8.  
  9.  
  10. String& String::trim (char *tok)
  11.     {
  12.     char *src =s;            // hold this->s  locally for efficiency.
  13.     
  14.     if (! ( tok==NULL || src==NULL ) )
  15.         {
  16.         int ns = n;
  17.         int ntok = strlen(tok);
  18.     
  19.         while (--ns >= 0)        // in the loop ns is index to last char=strlen()-1
  20.             {
  21.             if ( String::findchr ( tok, ntok, src[ns] ) >=0  )
  22.                 {
  23.                 src[ns] = 0;
  24.                 }
  25.             else
  26.                 {
  27.                 break;
  28.                 }
  29.             }
  30.         n= ns+1;                // add 1, now gives # bytes, index to term. NULL
  31.     
  32.         if ( ns== -1 )  destruct();        // free string if no bytes remain.
  33.         }
  34.     return  *this; /* strim() */
  35.  
  36.  
  37.     }
  38.